/**
 * Created by zhangligang
 * Email: tzhang2450@163.com
 * Date: 2019/1/19
 * Time: 23:41
 */
$(function () {

    sendAjax('/v1/manager/increase/score/detail.json', 'get', {id: $('.increase-id').val()}, function (json) {
        $('.increase-title').text(json.body.title);
        $('.increase-create-time').text(json.body.created_at);
        $('.increase-content').html(json.body.content);
        if (json.body.attachment) {
            $('.increase-attachment').parents('.form-group').removeClass('hidden');
            $('.increase-attachment a').attr('href', json.body.attachment);
            $('.img-increase-attachment').attr('src', json.body.attachment);
        } else {
            $('.increase-attachment').parents('.form-group').remove();
        }
        if (json.body.score > 0) {
            $('.increase-score').val(json.body.score);
        }
    });

    $('.btn-save').on('click', function(){
        var department_id = $('.department-id').val();
        var data = {
            id: $('.increase-id').val(),
            score: $('.increase-score').val()
        };

        if (checkForm(data)) {
            saveData('/v1/manager/save/department/increase', {params:data}, '/manager/department/increase-detail-'+department_id+'.html', '打分完成');
        }
    });
});

function checkForm(data) {
    if (data.score == '') {
        alertTip('分数不能为空');
        return false;
    }
    return true;
}